//
// DefaultExceptionAction.cpp
// Usage: Default "exception action" routine
// Create Date: 2009-03-18
// Creator: MaJiuyue
//
#include <NewLife.h>
#include "DefaultExceptionAction.h"
#include "bootutil.h"
#include "../schedule/Process.h"

char DefaultExceptionAction::err_description[][64] = {	
	"#DE Divide Error",
	"#DB RESERVED",
	"#!  NMI Interrupt",
	"#BP Breakpoint",
	"#OF Overflow",
	"#BR BOUND Range Exceeded",
	"#UD Invalid Opcode (Undefined Opcode)",
	"#NM Device Not Available (No Math Coprocessor)",
	"#DF Double Fault",
	"    Coprocessor Segment Overrun (reserved)",
	"#TS Invalid TSS",
	"#NP Segment Not Present",
	"#SS Stack-Segment Fault",
	"#GP General Protection",
	"#PF Page Fault",
	"#!  (Intel reserved. Do not use.)",
	"#MF x87 FPU Floating-Point Error (Math Fault)",
	"#AC Alignment Check",
	"#MC Machine Check",
	"#XF SIMD Floating-Point Exception"
};

void DefaultExceptionAction::operator() (u32 vec_no, u32 err_code, u32 eip, u32 cs, u32 eflags)
{
	kprintf("\n\nException! --> %s\n", err_description[vec_no]);
	kprintf("PID: %d\n", GetCurrentProcess()->GetPID());
	kprintf("EFLAGS: 0x%x\n    CS: 0x%x\n   EIP: 0x%x\n", eflags, cs, eip);
	if(err_code != 0xFFFFFFFF)
		kprintf("Error code: %x", err_code);
	panic("Unprocesseed exception!");
}

